import request from "@/utils/request";
import request3 from "@/utils/request3";


// 交易报表 数据看板 sort 1 月 2 日 3 周 4 季度 5年
export function getjiaoyibaobiao(year, month, day, week, quarter, id, sort) {
  let url =''
  if (sort === 1) {
    url = "aggs/market/monthlySales";
  } else if (sort === 2) {
    url = "aggs/market/dailySales";
  } else if (sort === 3) {
    url = "aggs/market/weeklySales";
  } else if (sort === 4) {
    url = "aggs/market/quarterlySales";
  } else if (sort === 5) {
    url = "aggs/market/yearlySales";
  }
  const formData = new FormData();
  formData.append("year", year);
  formData.append("month", month);
  formData.append("day", day);
  formData.append("quarter", quarter);
  formData.append("week", week);
  formData.append("id", id);
  const data = formData;
  return request3({
    url: url,
    method: "post",
    data
  });
}

// 交易额趋势 sort 1 月 2 日 3 周 4 季度 5年
export function getjiaoyiequshi(year, month, day, week, quarter, id, sort) {
  let url = "";
  if (sort === 1) {
    url = "aggs/market/dailyHistogram";
  } else if (sort === 2) {
    url = "aggs/market/hourlyHistogram";
  } else if (sort === 3) {
    url = "aggs/market/dailyHistogramForWeek";
  } else if (sort === 4) {
    url = "aggs/market/monthlyHistogramForQuarter";
  } else if (sort === 5) {
    url = "aggs/market/monthlyHistogram";
  }
  const formData = new FormData();
  formData.append("id", id);
  formData.append("year", year);
  formData.append("month", month);
  formData.append("day", day);
  formData.append("week", week);
  formData.append("quarter", quarter);
  const data = formData;
  return request3({
    url: url,
    method: "post",
    data
  });
}

// 品类交易额/量/客单价 sort 1 月 2 日 3 周 4 季度 5年
export function getpinleijiaoyie(year, month, day, week, quarter, id, sort){
  let url = "";
  if (sort === 1) {
    url = "aggs/market/monthlyTopType";
  } else if (sort === 2) {
    url = "aggs/market/dailyTopType";
  } else if (sort === 3) {
    url = "aggs/market/weeklyTopType";
  } else if (sort === 4) {
    url = "aggs/market/quarterlyTopType";
  } else if (sort === 5) {
    url = "aggs/market/yearlyTopType";
  }
  const formData = new FormData();
  formData.append("id", id);
  formData.append("year", year);
  formData.append("month", month);
  formData.append("day", day);
  formData.append("week", week);
  formData.append("quarter", quarter);
  const data = formData;
  return request3({
    url: url,
    method: "post",
    data
  });
}

// 交易峰值分析 sort 1 月 2 日 3 周 4 季度 5年
export function getjiaoyifengzhi(year, month, day, week, quarter, id, sort) {
  let url = "";
  if (sort === 1) {
    url = "aggs/market/monthlyHistogramEx";
  } else if (sort === 2) {
    url = "aggs/market/dailyHistogramEx";
  } else if (sort === 3) {
    url = "aggs/market/weeklyHistogramEx";
  } else if (sort === 4) {
    url = "aggs/market/quarterHistogramEx";
  } else if (sort === 5) {
    url = "aggs/market/yearlyHistogramEx";
  }
  const formData = new FormData();
  formData.append("id", id);
  formData.append("year", year);
  formData.append("month", month);
  formData.append("day", day);
  formData.append("week", week);
  formData.append("quarter", quarter);
  const data = formData;
  return request3({
    url: url,
    method: "post",
    data
  });
}

// 单品交易额/量分析 sort 1 月 2 日 3 周 4 季度 5年
export function getdanpinjiaoyie(year, month, day, week, quarter, id, sort ) {
  let url = "";
  if (sort === 1) {
    url = "aggs/market/monthlyHostSales";
  } else if (sort === 2) {
    url = "aggs/market/dailyHostSales";
  } else if (sort === 3) {
    url = "aggs/market/weeklyHostSales";
  } else if (sort === 4) {
    url = "aggs/market/quarterHotSales";
  } else if (sort === 5) {
    url = "aggs/market/yearlyHostSales";
  }
  const formData = new FormData();
  formData.append("id", id);
  formData.append("year", year);
  formData.append("month", month);
  formData.append("day", day);
  formData.append("week", week);
  formData.append("quarter", quarter);
  formData.append("sort", 1);  // sort 1金额 2重量
  const data = formData;
  return request3({
    url: url,
    method: "post",
    data
  });
}








// 客流报表 数据看板
export function getkeliubaobiao(year, month, date, type) {
  let url = "";
  let data = {}
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v1/backend/visitor/report/link_ratio";
    data = { date, type }
  } else if(type === 'month') {
    url = "api/v1/backend/face/total/flow/trend";
    data = { year, month }
  }
  return request({
    url: url,
    method: "post",
    data
  })
}

// 客流趋势
export function getkeliuqushi(date, type) {
  let url = "";
  let data = {}
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v2/backend/concentrate/tendency/index";
    data = { date, type }
  } else if (type === 'month') {
    url = "api/v2/backend/tendency/index";
    data = { date }
  }
  return request({
    url: url,
    method: "post",
    data
  })
}

// 客流漏斗(月度)
export function getkeliuloudou(year, month, date, type) {
  let url = "";
  let data = {}
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v1/backend/visitor/report/flow_funnel";
    data = { date, type }
  } else if (type === 'month') {
    url = "api/v1/backend/face/month/low_funnel";
    data = { year, month }
  }
  return request({
    url: url,
    method: "post",
    data
  })
}

// 客群画像
export function getkequnhuaxiang(year, month, date, type) {
  let url = "";
  let data = {}
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v1/backend/visitor/report/age_hour";
    data = { date, type }
  } else if (type === 'month') {
    url = "api/v1/backend/face/month/age_hour";
    data = { year, month }
  }
  return request({
    url: url,
    method: "post",
    data
  })
}

// 客群画像(人数)
export function getkequnhuaxiangsex(startTime, endTime, date, type) {
  let url = "";
  let data = {}
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v1/backend/visitor/report/sex_count";
    data = { date, type }
  } else if (type === 'month') {
    url = "api/v1/backend/read_sense/gender";
    data = { startTime, endTime }
  }
  return request({
    url: url,
    method: "post",
    data
  })
}

// 客流峰值分析(饼图)
export function getkeliufengzhi(date, type) {
  let url = "";
  let data = { date, type }
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v2/backend/concentrate/tendency/peak";
  } else if (type === 'month') {
    url = "api/v2/backend/tendency/peak";
  }
  return request({
    url: url,
    method: "post",
    data
  })
}

// 客流峰值分析(柱状图)
export function getweekkeliufengzhi(date, type) {
  let url = "";
  let data = { date, type }
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v2/backend/concentrate/tendency/week/peak";
  } else if (type === 'month') {
    url = "api/v2/backend/tendency/week/peak";
  }
  return request({
    url: url,
    method: "post",
    data
  })
}

/**
 * 时段客流热力图
 */
export function getRegionalChartsData(startDate, endDate, date, type) {
  let url = "";
  let data = {}
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v1/backend/visitor/report/entrance_analysis";
    data = { date, type }
  } else if (type === 'month') {
    url = "api/v1/backend/face/regional/analysis";
    data = { startDate, endDate }
  }
  return request({
    url: url,
    method: 'post',
    data
  })
}

// 回访活跃度分析(饼图1)
export function getFrequentActivities(targetDate, date, type) {
  let url = "";
  let data = {}
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v1/backend/visitor/report/interval_tend";
    data = { date, type }
  } else if (type === 'month') {
    url = "api/v1/backend/face/visit/interval";
    data = { targetDate }
  }
  return request({
    url: url,
    method: 'post',
    data
  })
}

// 回访活跃度分析(饼图1)
export function getFrequentActivities2(targetDate, date, type) {
  let url = "";
  let data = {}
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v1/backend/visitor/report/visit_count";
    data = { date, type }
  } else if (type === 'month') {
    url = "api/v1/backend/face/month/visit/count";
    data = { targetDate }
  }
  return request({
    url: url,
    method: 'post',
    data
  })
}


// 检测报表 数据看板
export function getjiancebaobiao(date, type) {
  const data = { date, type }
  let url = "";
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v2/backend/concentrate/check/total/list";
  } else if (type === 'month') {
    url = "api/v2/backend/check/total/list";
  }
  return request({
    url: url,
    method: "post",
    data
  })
}

// 检测趋势
export function getjiancequshi(date, type) {
  const data = { date, type }
  let url = "";
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v2/backend/concentrate/check/tendency";
  } else if (type === 'month') {
    url = "api/v2/backend/check/tendency";
  }
  return request({
    url: url,
    method: "post",
    data
  })
}

// 检测品类分布
export function getjiancepinleifenbu(date, type) {
  const data = { date, type };
  let url = "";
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v2/backend/concentrate/check/business_type";
  } else if (type === 'month') {
    url = "api/v2/backend/check/business_type";
  }
  return request({
    url: url,
    method: "post",
    data
  });
}

// 不合格产品分布
export function getbuhegechanpin(date, type) {
  const data = { date, type };
  let url = "";
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v2/backend/concentrate/check/goods";
  } else if (type === 'month') {
    url = "api/v2/backend/check/goods";
  }
  return request({
    url: url,
    method: "post",
    data
  });
}

// 不合格摊位
export function getbuhegetanwei(date, type) {
  const data = { date, type };
  let url = "";
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v2/backend/concentrate/check/business";
  } else if (type === 'month') {
    url = "api/v2/backend/check/business";
  }
  return request({
    url: url,
    method: "post",
    data
  });
}

// 不合格时间
export function getbuhegeshijian(date, type) {
  const data = { date, type }
  let url = "";
  if (type === 'day' || type === 'week' || type === 'quarter' || type === 'year') {
    url = "api/v2/backend/concentrate/check/time";
  } else if (type === 'month') {
    url = "api/v2/backend/check/time";
  }
  return request({
    url: url,
    method: "post",
    data
  })
}
